package demo19;

import java.io.File;
import java.io.IOException;

public class demo19_2 {

    public static void searchFile(File dir, String fileName) throws Exception {
        if (dir == null || dir.isFile() || !dir.exists()){
            return;
        }
        else {
            File[] files = dir.listFiles();
            if (files != null && files.length > 0){
                for (File file : files) {
                    if (file.isFile()){
                        if (file.getName().contains(fileName)){
                            System.out.println("找到了：" + file.getAbsoluteFile());
                            Runtime runtime = Runtime.getRuntime();
                            runtime.exec(file.getAbsolutePath());
                            return;

                        }
                    }
                    else {
                        searchFile(file, fileName);
                    }
                }
            }
        }

    }
    public static void main(String[] args) throws Exception {
        searchFile(new File("C:/"), "QQ.exe");

    }

}
